package com.woniu.controller;

import com.sun.javafx.collections.MappingChange;
import com.woniu.pojo.PreOrder;
import com.woniu.service.OrderService;
import com.woniu.dto.MyDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class OrderController {
    @Autowired
    private OrderService orderService;
   @PostMapping("/createorder")
   @ResponseBody
    public Map order(@RequestBody PreOrder preOrder){
       preOrder.setStatus("未支付");
      Map map=new HashMap();
       try {
           orderService.createorder(preOrder);
           map.put("code",200);
           map.put("msg","创建订单成功！请于15分支内支付");
           return map;
       }catch (Exception e){
           e.printStackTrace();
           map.put("code",-200);
           map.put("msg","创建订单失败！请稍后再试");
           return map;
       }


    }
}
